package config;

import com.hjt.zhibo.action.CommonAction;
import com.hjt.zhibo.model.HotCatalog;
import com.hjt.zhibo.model.PlatFormCatalog;
import com.hjt.zhibo.model.PlatFormRoom;
import com.hjt.zhibo.model.WebCatalog;
import com.hjt.zhibo.model.WebNotice;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.scheduler.SchedulerPlugin;

public class MyJFinalConfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		//文件配置
		PropKit.use("config/text_config.txt");
		me.setDevMode(PropKit.getBoolean("devMode", false));
	}

	/**
	 *	路由配置
	 */
	@Override
	public void configRoute(Routes me) {
		
		me.add("/", CommonAction.class);
		
	}

	/**
	 * 插件配置
	 */
	@Override
	public void configPlugin(Plugins me) {
		
		//C3P0配置
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
		me.add(c3p0Plugin);
		
		// 配置ActiveRecord数据
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		//配置表映射
		arp.addMapping("platform_catalog", "platform_catalog_id", PlatFormCatalog.class);
		arp.addMapping("platform_room", "platform_room_id", PlatFormRoom.class);
		arp.addMapping("hot_catalog", "hot_catalog_id", HotCatalog.class);
		arp.addMapping("web_catalog", "web_catalog_id", WebCatalog.class);
		arp.addMapping("web_notice", "web_catalog_id", WebNotice.class);
		
		
		//定时器配置
		SchedulerPlugin sp = new SchedulerPlugin("/config/job.properties");
        me.add(sp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

}
